# src/schemas/sys_objects.py
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


class SysObjectsBase(BaseModel):
    object_name: str = Field(..., max_length=64, description="对象名称")
    alias: Optional[str] = Field(None, max_length=64, description="对象别名")
    description: Optional[str] = Field(None, max_length=128, description="对象说明")
    object_type: Optional[str] = Field(None, max_length=64, description="T:表 V:视图 P:存储过程 FT:函数表 FC:函数值")
    inner_object: Optional[str] = Field(None, max_length=64, description="关联对象")
    inner_id: Optional[str] = Field(None, max_length=36, description="关联对象号码")
    cols_per_row: Optional[int] = Field(None, ge=0, description="排序")
    sort: Optional[int] = Field(None, ge=0, description="排序")
    enabled: bool = Field(True, description="是否启用 1-启用 0-禁用")

    # 软删除
    deletion_mark: bool = False
    deletion_reason: Optional[str] = None
    deletion_date: Optional[datetime] = None
    deletion_by: Optional[str] = None

    # 审计
    create_date: Optional[datetime] = None
    creator_by: Optional[str] = None
    last_updated_date: Optional[datetime] = None
    last_updated_by: Optional[str] = None


class SysObjectsCreate(SysObjectsBase):
    api_id: Optional[str] = Field(None, max_length=36, description="API主键，用于关联其他系统")


class SysObjects(SysObjectsBase):
    id: str
    api_id: Optional[str] = Field(None, max_length=36, description="API主键，用于关联其他系统")

    class Config:
        from_attributes = True
